/**
 * https://leetcode.cn/problems/number-of-visible-people-in-a-queue/submissions/588254964/
 * 1944. 队列中可以看到的人数
 * difficulty 2024.12.20
 * 单调栈
 */

class Solution {
public:
    vector<int> canSeePersonsCount(vector<int>& heights) {
        stack<int> st;
        int n=heights.size();
        vector<int> v(n,0);
        for(int i=n-1;i>=0;--i){
             while(!st.empty()&&st.top()<heights[i]){
                st.pop();
                v[i]+=1;
             }if(!st.empty())
                v[i]+=1;
            st.push(heights[i]);
        }
        return v;
    }
};